package saxion.speelveld.spaceengineer.controller;

import java.util.ArrayList;

import saxion.speelveld.spaceengineer.R;
import saxion.speelveld.spaceengineer.model.Building;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class buildingsSimpleAdapter extends ArrayAdapter<Building>
{
	private Context context;

	private ArrayList<Building> currentBuildings;

	public buildingsSimpleAdapter(Context context, ArrayList<Building> currentBuildings)
	{
		super(context, R.layout.building_item_layout, currentBuildings);
		this.currentBuildings = currentBuildings;
		this.context = context;
		this.init(context, currentBuildings);
	}

	private void init(Context context, ArrayList<Building> currentBuildings)
	{
		this.context = context;
		this.currentBuildings = currentBuildings;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.building_item_layout, parent, false);

		TextView textView = (TextView) convertView.findViewById(R.id.tv_building_label);
		ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_building_image);

		textView.setText("Level " + currentBuildings.get(position).getBuildingLevel() + " - "
			+ currentBuildings.get(position).getBuildingName());
		int size = 32 * (int) (convertView.getResources().getDisplayMetrics().density);
		imageView.setMinimumWidth(size);
		imageView.setMinimumHeight(size);
		imageView.setImageResource(this.currentBuildings.get(position).getPreviewResourceImageId());

		return convertView;

	}

}
